<?php
require_once ('../connexion.php');
$nom=$_POST['nom'];
$idProd=$_POST['id'];
$type=$_POST['type'];
?>
<h1><?php echo $type;?></h1>
<div class="cadreContenu">
	<h3><?php echo $nom;?></h3>
	<?php 
		// Selection du produits
	try{
		$sql = 'SELECT * FROM produits WHERE id=:idProd';
		$select = $connection->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
		$select->execute(array(':idProd' => $idProd ));
		$enregistrement = $select->fetch(PDO::FETCH_OBJ);
		
		if ($enregistrement==true){
			?>
			<p><?php echo $enregistrement->contenu;?></p>
			
			<table class="thumbnail">
				<tr>
					<?php 
					try{
					?>
						<td class="thumbnailContent">	
						<?php
						
						$sql = 'SELECT * FROM images WHERE idProduits=:idProd';
						$select = $connection->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
						$select->execute(array(':idProd' => $idProd ));
						$enregistrement = $select->fetch(PDO::FETCH_OBJ);
					
						$select->execute(array(':idProd' => $idProd ));
						
						?>
							<div id="divLargeImg">
								<img id="imgContent" src="images/<?php echo $enregistrement->chemin;?>"/>
							</div>
							<h3 id="h3Description" class="titleDescriptionGalery"><?php echo $enregistrement->nom;?></h3>
							<p id="descriptionGalerry"><?php echo $enregistrement->description;?></p>
						</td>
						<td class="thumbnailChoice">	
							<?php	while($enregistrement2 = $select->fetch(PDO::FETCH_OBJ)){
								$nom=preg_replace('/"/','&#34;',$enregistrement2->nom); // convertie toutes les "
								$nom=preg_replace('/\'/','&#180;',$nom); // convertie toutes les '
			
								$description=preg_replace('/"/','&#34;',$enregistrement2->description); // convertie toutes les "
								$description=preg_replace('/\'/','&#180;',$description); // convertie toutes les '			
							?>
								<div>
									<img onMouseOver="return loadLargeImage('<?php echo $enregistrement2->chemin;?>','<?php echo $description;?>','<?php echo $nom;?>');" class="littleImage" src="images/<?php echo $enregistrement2->chemin;?>" />					
								</div>
							<?php } ?>					
						</td>
					<?php 
					}catch(Exception $e){
						echo "<h3 class='error'>Impossible de charger les images</h3>";
					}
					?>		
				</tr>
			</table>
			<?php
		}
	}catch(Exception $e){
		echo "<h3 class='error'>Impossible de charger le produit</h3>";
	}
	?>
</div>